<?php
/* 分类控制器
* @Author: Jerry-chen
* @Date:   2014-07-06 22:07:19
* @Last Modified time: 2014-07-15 16:31:02
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/

class CategoryControl extends CommonControl
{
	public $model;

	public function __auto()
	{
		$this->model = K('Category');
	}
	/**
	 * [index 分类列表]
	 * @return [type] [description]
	 */
	public function index()
	{

		// 查找出所有的分类
		$cateData = $this->model->get_all();
		// p($cateData);die;
		//目录树
		$cateData = Data::tree($cateData,'catename','cateid');
		//分配属性
		$this->assign('cateData',$cateData);
		// p($cateData);
		$this->display();
	}
	/**添加分类
	 * [add_category description]
	 */
	public function add_category()
	{
		//先查出所有的类型数据
		$typeModel = K('Type');
		$typeDate = $typeModel->get_all();
		//数据分配
		// p($typeDate);die;
		$this->assign('typeDate',$typeDate);
		//添加数据
		if(IS_POST)
		{
			$this->model->add_();
			$this->success('添加成功',U('index'));
		}

		$this->display('add.html');

	}
	/**
	 * [add_son 添加子分类]
	 */
	public function add_son()
	{
		// p(Q('get.'));die;
		//将GET参数传过来的父级名称分配出去
		$fathername = Q('get.fathername');
		$this->assign('fathername',$fathername);


		if(IS_POST)
		{
			$this->model->add_();
			$this->success('添加成功',U('index'));
		}
		$this->display();
	}
	/**
	 * [edit 修改]
	 * @return [type] [description]
	 */
	public function edit()
	{
		//查找出旧数据
		$cateid = Q('get.cateid');
		//组合WHERE条件
		$where = array('cateid'=>$cateid);
		$cateData = $this->model->get_one($where);
		// p($cateData);die;
		// 分配数据
		$this->assign('cateData',$cateData);
		
		// 查出所有分类
		$allcate = $this->model->get_all();
		$this->assign('allcate',$allcate);
		// p($allcate);die;
		//查出所有的
		$type = K('Type');
		
		$typeData = $type->get_all();
		// p($typeData);die;
		$this->display();
	}
	public function del()
	{
		$cateid =Q('get.cateid'); 
		$this->model->del(array('cateid'=>$cateid));
		$this->success('删除成功','index');
	}
}

?>
